package com.ksc.storekeeper.client.view.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.PopupViewImpl;
import com.ksc.storekeeper.client.view.ProductDetailsView;
import com.ksc.storekeeper.shared.dto.ProductDTO;

public class ProductDetailsViewImpl extends PopupViewImpl implements ProductDetailsView {

	private final Widget widget;
	
	@Inject
	public ProductDetailsViewImpl(EventBus eventBus) {
		super(eventBus);
		widget=uiBinder.createAndBindUi(this);
	}

	@UiField
	Button closeButton;
	
	@UiField
	Image productImage;
	
	@UiField
	Label productName;
	
	@UiField
	Label productCategory;
	
	@UiField
	Label productCode;
	
	@UiField
	Label productDescription;
	
	@UiField
	Label productPrice;

	private static ProductDetailsViewImplUiBinder uiBinder = GWT.create(ProductDetailsViewImplUiBinder.class);

	interface ProductDetailsViewImplUiBinder extends UiBinder<Widget, ProductDetailsViewImpl> {
	}
	
	@UiHandler("closeButton")
	public void closeClicked(ClickEvent event){
		this.hide();
	}

	@Override
	public Widget asWidget() {
		return widget;
	}
	
	@Override
	public void displayProduct(ProductDTO productDTO){
		productImage.setUrl("images/product/"+productDTO.getImageUrl());
		productName.setText(productDTO.getName());
		productCode.setText(productDTO.getCode());
		productDescription.setText(productDTO.getDescription());
		productCategory.setText(productDTO.getCategory().getValue());
		productPrice.setText("Rs. 100");
	}

}
